added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSInteractiveWindowsService / WTSHelper.cs
blobf93cbb9b14090905550057dd32092928a2ed1938
1 /******************************** Module Header ********************************\
2 * Module Name: WTSHelper.cs
3 * Project: CSInteractiveWindowsService
4 * Copyright (c) Microsoft Corporation.
5 *
6 * To be finished - Jialiang Ge
7 * Ref: http://files.codes-sources.com/fichier.aspx?id=47023&f=WTSLib/WTSLib/WTSHelper.cs
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 \*******************************************************************************/
18 using System;
19 using System.Text;
20 using System.Runtime.InteropServices;
23 namespace CSInteractiveWindowsService
25 class WTSHelper
27 /// <summary>
28 /// Retrieves the Remote Desktop Services session that is currently
29 /// attached to the physical console. The physical console is the monitor,
30 /// keyboard, and mouse. If there is no session attached to the physical
31 /// console, (for example, if the physical console session is in the
32 /// process of being attached or detached), this function returns
33 /// 0xFFFFFFFF.
34 /// </summary>
35 public static uint ActiveConsoleSessionId
37 get { return WTSGetActiveConsoleSessionId(); }
40 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
41 private static extern uint WTSGetActiveConsoleSessionId();
43 [DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
44 [return: MarshalAs(UnmanagedType.Bool)]
45 private static extern bool WTSEnumerateSessions(IntPtr hServer,
46 uint reserved, uint version, out IntPtr ppSessionInfo, out uint count);
48 [DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
49 private static extern bool WTSQuerySessionInformation(IntPtr hServer,
50 uint sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer,
51 out uint bytesReturned);
53 [DllImport("wtsapi32.dll", CharSet = CharSet.Auto, SetLastError = false)]
54 private static extern void WTSFreeMemory(IntPtr memory);
57 public static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
61 /// <summary>
62 /// The WTS_SESSION_INFO structure contains information about a client
63 /// session on a Remote Desktop Session Host (RD Session Host) server.
64 /// </summary>
65 [StructLayout(LayoutKind.Sequential)]
66 struct WTS_SESSION_INFO
68 public uint SessionID;
70 [MarshalAs(UnmanagedType.LPTStr)]
71 public string WinStationName;
73 public WTS_CONNECTSTATE_CLASS State;
77 /// <summary>
78 /// Specifies the connection state of a Remote Desktop Services session.
79 /// </summary>
80 enum WTS_CONNECTSTATE_CLASS
82 WTSActive,
83 WTSConnected,
84 WTSConnectQuery,
85 WTSShadow,
86 WTSDisconnected,
87 WTSIdle,
88 WTSListen,
89 WTSReset,
90 WTSDown,
91 WTSInit
95 /// <summary>
96 /// The WTS_INFO_CLASS enumeration type contains values that indicate the
97 /// type of session information to retrieve in a call to the
98 /// WTSQuerySessionInformation function.
99 /// </summary>
100 enum WTS_INFO_CLASS
102 WTSInitialProgram,
103 WTSApplicationName,
104 WTSWorkingDirectory,
105 WTSOEMId,
106 WTSSessionId,
107 WTSUserName,
108 WTSWinStationName,
109 WTSDomainName,
110 WTSConnectState,
111 WTSClientBuildNumber,
112 WTSClientName,
113 WTSClientDirectory,
114 WTSClientProductId,
115 WTSClientHardwareId,
116 WTSClientAddress,
117 WTSClientDisplay,
118 WTSClientProtocolType,
119 WTSIdleTime,
120 WTSLogonTime,
121 WTSIncomingBytes,
122 WTSOutgoingBytes,
123 WTSIncomingFrames,
124 WTSOutgoingFrames,
125 WTSClientInfo,
126 WTSSessionInfo